﻿using MediatR;
using WeekWork929.Api.Write.Appliaction.Commond;
using WeekWork929.Domain;
using WeekWork929.ErrorCode;
using WeekWork929.infrastrunceture;

namespace WeekWork929.Api.Write.Appliaction.CommondHandler
{
    public class MasenDelCommondHandler : IRequestHandler<MasenDelCommond, ApiResult<int>>
    {
        private readonly IBaseIRepository<Workmend> workMed;

        public MasenDelCommondHandler(IBaseIRepository<Workmend> workMed)
        {
            this.workMed = workMed;
        }

        public async Task<ApiResult<int>> Handle(MasenDelCommond request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code=ApiEnum.删除成功;
            result.Msg=ApiEnum.删除成功.ToString();
            var list= workMed.GetAll().Where(x=>x.WorkmendId==request.WorkmendId).FirstOrDefault();
            if(list!=null)
            {
                list.Isdelete=true;
                await workMed.Update(list);
            }
            return await Task.FromResult(result);
        }
    }
}
